What is @aws-crypto/kms-keyring-node?
@aws-crypto/kms-keyring-node is an AWS SDK package that provides keyring implementations for AWS Key Management Service (KMS). It allows you to encrypt and decrypt data using AWS KMS keys in a Node.js environment.
What are @aws-crypto/kms-keyring-node's main functionalities?
Encrypting Data
This feature allows you to encrypt data using a KMS key. The code sample demonstrates how to create a KMS keyring and use it to encrypt a plaintext message.
const { KmsKeyringNode, buildClient, CommitmentPolicy } = require('@aws-crypto/kms-keyring-node');
const { encrypt } = require('@aws-crypto/client-node');
const keyring = new KmsKeyringNode({ generatorKeyId: 'arn:aws:kms:us-west-2:123456789012:key/abcd-1234-efgh-5678' });
const plaintext = Buffer.from('Hello, world!');
(async () => {
const { result } = await encrypt(keyring, plaintext);
console.log(result); // Encrypted data
})();
Decrypting Data
This feature allows you to decrypt data that was encrypted using a KMS key. The code sample demonstrates how to create a KMS keyring and use it to decrypt an encrypted message.
const { KmsKeyringNode, buildClient, CommitmentPolicy } = require('@aws-crypto/kms-keyring-node');
const { decrypt } = require('@aws-crypto/client-node');
const keyring = new KmsKeyringNode({ generatorKeyId: 'arn:aws:kms:us-west-2:123456789012:key/abcd-1234-efgh-5678' });
const encryptedData = Buffer.from('...'); // Encrypted data from previous step
(async () => {
const { plaintext } = await decrypt(keyring, encryptedData);
console.log(plaintext.toString()); // Decrypted data
})();
Multi-Region Keyring
This feature allows you to create a multi-region keyring that can use multiple KMS keys from different regions. The code sample demonstrates how to configure a keyring with multiple KMS key ARNs.
const { KmsKeyringNode } = require('@aws-crypto/kms-keyring-node');
const keyring = new KmsKeyringNode({
generatorKeyId: 'arn:aws:kms:us-west-2:123456789012:key/abcd-1234-efgh-5678',
keyIds: [
'arn:aws:kms:us-east-1:123456789012:key/abcd-1234-efgh-5678',
'arn:aws:kms:eu-west-1:123456789012:key/abcd-1234-efgh-5678'
]
});
console.log(keyring);
Other packages similar to @aws-crypto/kms-keyring-node
aws-sdk
The aws-sdk package is the official AWS SDK for JavaScript, which includes support for AWS KMS among many other AWS services. It provides a more general-purpose interface for interacting with AWS services, including KMS, but does not offer the same high-level abstractions for encryption and decryption as @aws-crypto/kms-keyring-node.
node-forge
node-forge is a JavaScript library for implementing various cryptographic functions, including encryption and decryption. While it does not integrate directly with AWS KMS, it provides a wide range of cryptographic utilities that can be used for similar purposes. It requires more manual setup and does not offer the same seamless integration with AWS services.
crypto-js
crypto-js is a popular library for cryptographic operations in JavaScript. It provides a variety of cryptographic algorithms and utilities but does not integrate with AWS KMS. It is useful for general-purpose cryptographic needs but lacks the specific key management features provided by @aws-crypto/kms-keyring-node.
aws-encryption-sdk-javascript
The AWS Encryption SDK for JavaScript is a client-side encryption library
designed to make it easy for everyone to encrypt
and decrypt data using industry standards and best practices.
It uses a data format compatible with the AWS Encryption SDKs in other languages.
For more information on the AWS Encryption SDKs in all languages,
see the Developer Guide.
This package should only be used as part of the AWS Encryption SDK for Javascript.
For more information about the packages in this project
and how they can be used together,
see the main node package readme
Installing
npm install @aws-crypto/kms-keyring-node
Testing
npm test
License
This SDK is distributed under the
Apache License, Version 2.0,
see LICENSE.txt and NOTICE.txt for more information.